package com.cy.pj.db10.contorller;

import com.cy.pj.db10.pojo.Db10;
import com.cy.pj.db10.service.Db10Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class Db10Contorller {

    @Autowired
    private Db10Service db10Service;

    //查询、搜索
    @RequestMapping({"/doFindDb10/{name}","/doFindDb10"})
    public String doFindDb10(@PathVariable(required = false) String name, Model model){
        List<Db10> list = db10Service.findDb10(name);
        model.addAttribute("list",list);
        return "db10";
    }

    //新增
    @RequestMapping("/doAddUI")
    public String doAddUI(){
        return "db10_add";
    }
    @RequestMapping("/doSaveDb10")
    public String doSaveDb10(Db10 db10){
         db10Service.saveDb10(db10);
         return "redirect:/doFindDb10";
    }


    //修改
    @RequestMapping("/doFindById/{id}")
    public String  doFindById(@PathVariable("id")Integer id,Model model){
        Db10 db10 = db10Service.findById(id);
        model.addAttribute("db10",db10);
        return "db10_update";
    }
    @RequestMapping("/doUpdateDb10")
    public  String doUpdateDb10(Db10 db10){
       db10Service.updateDb10(db10);
       return "redirect:/doFindDb10";
    }

    //删除
    @RequestMapping("/doDeleteById/{id}")
    public String doDeleteById(@PathVariable("id")Integer id){
        db10Service.deleteById(id);
        return "redirect:/doFindDb10";
    }


}
